<?php
/**
 * Created by PhpStorm.
 * User: Sergey
 * Date: 23.02.14
 * Time: 23:17
 */

require_once BASE_DQ_PLUGIN_PATH . "classes/QuizDao.php";
require_once BASE_DQ_PLUGIN_PATH . "classes/UserDao.php";

$quizDao = new QuizDao();
$userDao = new UserDao();

if (isset($_REQUEST["action"])
    && $_REQUEST["action"] == "remove"
    && isset($_REQUEST["id"])
    && intval($_REQUEST["id"]) > 0
) {
    $quizDao->remove(intval($_REQUEST["id"]));
    header('Location: ' . strtok($_SERVER["REQUEST_URI"], '?') . "?page=" . $_GET["page"]);
}

$quizzes = $quizDao->getAll();
?>

<table class="wp-list-table widefat fixed posts">
    <thead>
    <tr>
        <th style="width: 5%;">Id</th>
        <th>Название</th>
        <th style="width: 35%;">Описание</th>
        <th>Начало активности</th>
        <th>Конец активности</th>
        <th>Автор теста</th>
        <th>Операции</th>
    </tr>
    </thead>
    <tbody>
    <? foreach ($quizzes as $quiz) { ?>
        <tr>
            <td><?= $quiz->id ?></td>
            <td>
                <a href="<?= strtok($_SERVER["REQUEST_URI"], "?") . "?page=distant-quiz/quiz-form.php&id=" . $quiz->id ?>"><?= $quiz->name ?></a>
            </td>
            <td><?= $quiz->description ?></td>
            <td><?= $quiz->startDate->format("d.m.Y") ?></td>
            <td><?= $quiz->endDate->format("d.m.Y") ?></td>
            <td><?= $tutorDao->getById($quiz->id)->displayName; ?></td>
            <td>
                <a href="<?= $_SERVER["REQUEST_URI"] . "&action=remove&id=" . $quiz->id ?>"
                   class="jquery-button">Удалить</a>
            </td>
        </tr>
    <? } ?>
    </tbody>
</table>